package com.weixin.engine.daily.thread;

/**
 * setUncaughtExceptionHandler
 *
 * @author wangchunhui
 * @date 2022/11/8 10:25
 */
public class SetUncaughtExceptionHandlerTest {
    public static void main(String[] args) {

        Thread t = new Thread(new AdminThread(), "线程t");

        t.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
            @Override
            public void uncaughtException(Thread t, Throwable e) {
                System.out.println(t.getName() + " throws exception: " + e);
            }
        });
        t.start();

    }

    static class AdminThread implements Runnable {
        @Override
        public void run() {
            System.out.println(Thread.currentThread().getName() + "========");
            throw new RuntimeException("运行期异常");
        }
    }
}